package com.nbgroup.controller;

import com.github.pagehelper.Page;
import com.nbgroup.pojo.Role;
import com.nbgroup.pojo.common.PageBean;
import com.nbgroup.pojo.common.Result;
import com.nbgroup.pojo.dto.PageRoleDTO;
import com.nbgroup.pojo.dto.RoleDTO;
import com.nbgroup.pojo.dto.RoleDTO2;
import com.nbgroup.pojo.dto.RoleDTO3;
import com.nbgroup.service.RoleService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

@RestController
@Slf4j
@RequiredArgsConstructor
@Api(tags = "角色管理")
public class RoleController {
private final RoleService roleService;
@GetMapping("/system/role/list")
    @ApiOperation("角色分页搜索")
    public PageBean rolePageQuery(PageRoleDTO pageRoleDTO){
    PageBean pageBean=roleService.rolePageQuery(pageRoleDTO);
    return pageBean;
    }
    @PostMapping("/system/role")
    @ApiOperation("添加角色")
    public Result addRole(@RequestBody Role role){
    roleService.addRole(role);
    return Result.success();
    }
    @GetMapping("/system/role/{roleId}")
    @ApiOperation("查询回显")
    public Result queryById(@PathVariable Long roleId){
    Role role =roleService.queryById(roleId);
    return Result.success(role);
    }
    @PutMapping("/system/role")
    @ApiOperation("修改角色")
    public Result updateRole(@RequestBody Role role){
    roleService.updateRole(role);
    return Result.success();
    }
    @DeleteMapping("/system/role/{roleId}")
    @ApiOperation("删除角色")
    public Result deleteRole(@PathVariable Long roleId){
    roleService.deleteRole(roleId);
    return Result.success();
    }
    @PutMapping("/system/role/changeStatus")
    @ApiOperation("修改角色状态")
    public Result updateRoleStatus(@RequestBody RoleDTO roleDTO){
    roleService.updateRoleStatus(roleDTO);
    return Result.success();
    }
    @PutMapping("/system/role/dataScope")
    @ApiOperation("修改角色数据权限")
    public Result updateDataScope(@RequestBody RoleDTO3 roleDTO3){
    roleService.updateDataScope(roleDTO3);
    return Result.success();
    }
    @GetMapping("/system/role/export")
    @ApiOperation("角色数据导出")
    public Result roleExport(PageRoleDTO roleDTO){
    roleService.roleExport(roleDTO);
    return Result.success();
    }
}
